package com.ozo.easy.controller;

import com.ozo.easy.common.model.*;
import com.ozo.easy.common.log.annotation.LogAnno;
import com.ozo.easy.pojo.dto.SysNoticeSaveDTO;
import com.ozo.easy.pojo.dto.SysNoticeQueryDTO;
import com.ozo.easy.pojo.vo.SysNoticeVO;
import com.ozo.easy.service.ISysNoticeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;

/**
 * 通知 前端控制器
 *
 * @author ozo
 * @version 1.0
 * @date 2025-02-06 16:35:26
 */
@Tag(name = "通知")
@RequiredArgsConstructor
@RestController
@RequestMapping("/sysNotice")
public class SysNoticeController {

    private final ISysNoticeService sysNoticeService;

    @Operation(summary = "表格页")
    @GetMapping("/index")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("sysNotice/index");
        return modelAndView;
    }

    @Operation(summary = "添加页")
    @GetMapping("/addForm")
    public ModelAndView addForm() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("sysNotice/addForm");
        return modelAndView;
    }

    @Operation(summary = "编辑页")
    @GetMapping("/editForm/{id}")
    public ModelAndView editForm(@PathVariable Long id) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("data", sysNoticeService.detail(id));
        modelAndView.setViewName("sysNotice/editForm");
        return modelAndView;
    }

    @Operation(summary = "详情页")
    @GetMapping("/detailForm/{id}")
    public ModelAndView detailForm(@PathVariable Long id) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("data", sysNoticeService.detail(id));
        modelAndView.setViewName("sysNotice/detailForm");
        return modelAndView;
    }

    @LogAnno(value = "添加通知", module = "通知")
    @Operation(summary = "添加通知")
    @PostMapping("/add")
    public ResultVO<Void> add(@RequestBody @Valid SysNoticeSaveDTO saveDTO) {
        sysNoticeService.add(saveDTO);
        return ResultVO.success();
    }

    @LogAnno(value = "删除通知", module = "通知")
    @Operation(summary = "删除通知")
    @DeleteMapping("/remove")
    public ResultVO<Void> remove(@RequestBody @Valid BaseBatchDTO<Long> batchDTO) {
        sysNoticeService.remove(batchDTO);
        return ResultVO.success();
    }

    @LogAnno(value = "编辑通知", module = "通知")
    @Operation(summary = "编辑通知")
    @PutMapping("/edit")
    public ResultVO<Void> edit(@RequestBody @Validated(value = BaseValidDTO.Edit.class) SysNoticeSaveDTO saveDTO) {
        sysNoticeService.edit(saveDTO);
        return ResultVO.success();
    }

    @Operation(summary = "通知分页")
    @GetMapping("/page")
    public ResultVO<PageResult<SysNoticeVO>> page(@Valid BasePage basePage, SysNoticeQueryDTO queryDTO) {
        return ResultVO.success(sysNoticeService.page(basePage, queryDTO));
    }

}